<?php
/**
 * Created by PhpStorm.
 * User: aDaddy
 * Date: 2016/7/25
 * Time: 9:55
 */

namespace App\Model\LazyCommon;

use App\Base\BaseModel;
use Doctrine\Bundle\DoctrineBundle\Registry;
use App\Setting\LazyCommon\ConfCatSetting;
use Symfony\Component\HttpFoundation\Request;

class CCM extends ConfCatModel{
    public function createOption4Select($data)
    {
        return ["other"=>["choices"=>array_flip($data)]];
    }
    public function createOption4Radio($data)
    {
        return ["other"=>["choices"=>($data)]];
    }

    public function createSelectFromCategoryTree($data)
    {
        $re = [];
        foreach ($data as $item) {
            $id = $item["id"];
            $re[$item["name"]." [ $id ]"] = $item["id"];
        }
        return $re;
    }

    public function createSelectFromEntity($data,$key = "name")
    {
        $func = "get".ucfirst($key);
        $re = [];
        foreach ($data as $item) {

            $re[$item->$func()] = $item->getId();
        }
        return $re;
    }
}